﻿/// <reference path="Core.js" />
/// <reference path="jquery-1.9.1.js" />
var id;
$(function ()
{
    id = "ListInnerContainer";
    core.View.Load(EntityName, id);
    //zw
    $("span[title='筛选']").on('click', function ()
    {
        var Fiterpanel = $(this).siblings('.FilterDiv').eq(0);
        if (Fiterpanel.outerHeight() > 400)
        {
            Fiterpanel.css('padding-top', '0');
            Fiterpanel.find('.form-group').css("height", "200px");
            Fiterpanel.find('.form-group').css("overflow-y", "auto");
        }
    });
    //zw
    //添加中文日期格式模块
    $.fn.datetimepicker.dates['zh-CN'] = {
        days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
        daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
        daysMin: ["日", "一", "二", "三", "四", "五", "六", "日"],
        months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        today: "当前时间",
        suffix: [],
        meridiem: ["上午", "下午"]
    };

    $('.form-time').datetimepicker({
        language: 'zh-CN',
        format: 'yyyy-mm-dd hh:ii',
        weekStart: 1,
        autoclose: true
    });

    //zw-end
    //The First Line Written By ZYQ
    if (DoNotShowButton <= 0)
    {
        if (Privilege.CREATE > 0) $('#btn_add').css('display', 'inline-block');
        if (ViewName.toLowerCase().indexOf('deletedview') < 0 && Privilege.DELETE > 0) $('#btn_delete').css('display', 'inline-block');
        if (Privilege.ASSIGN > 0) $('#btn_assign').css('display', 'inline-block');
        if (ViewName.toLowerCase().indexOf('deletedview') >= 0 && Privilege.DELETE > 0)
        {
            $('#btn_recoverSoftDelete').css('display', 'inline-block');
        }
    }
    //The Final Line Written By ZYQ

    //滚动
    $("#ListContainer thead").css({ "background": "#F5F6FA" });
    $("div.table-responsive").scroll(function ()
    {
        var left = (-1) * $(this).scrollLeft();
        var top = $(this).scrollTop();
        //$("#ListContainer thead").css("left", left);
        $("#ListContainer-title").css("top", top);
    });

});


/// <reference path="Core.js" />
/// <reference path="jquery-1.9.1.js" />

if (typeof (core) == 'undefined')
    core = {};

core.View = {};
core.EntityName = {};
core.ViewName = {};
core.View.Url = {};

core.ViewField = {};
core.EntityOption = {};
core.EntityViews = {};
core.View.Orderby = {};
core.ListData = {};
core.View.Option = {};
core.View.OptionBackup = {};
core.View.isHaveFilter = {};
core.View.PageParam = {};

core.View.Load = function (entityname, id, ishaveSearch, ishaveView, option, InitShowView, DefaultViewName, isHaveFilter)
{

    //是否生成操作列
    if (typeof (option) != 'undefined')
        core.View.Option[id] = option;
    if (option == null)
        core.View.Option[id] = [];

    core.View.OptionBackup[id] = core.View.Option[id];

    //自动生成页面框架
    if (typeof (ishaveSearch) == 'undefined')
        ishaveSearch = true;
    if (typeof (ishaveView) == 'undefined')
        ishaveView = true;
    if (typeof (isHaveFilter) == 'undefined')
        isHaveFilter = true;
    if (typeof (InitShowView) == 'undefined')
        InitShowView = true;
    core.View.isHaveFilter[id] = isHaveFilter;
    if (typeof (DefaultViewName) == 'undefined' || DefaultViewName == null)
        DefaultViewName = ViewName;
    core.ViewName[id] = DefaultViewName;
    if (ishaveSearch)
    {
        $("#" + id).children().append(' <!--搜索框-->\
                                        <div class="col-xs-6" style=\"z-index:1\">\
                                            <div class="input-group">\
                                                <input type="text" class="form-control" name="txt_searchValue" onkeypress=\'if (event.keyCode == 13) core.View.Search("' + id + '")\' placeholder="搜索..." />\
                                                <span class="input-group-btn">\
                                                    <button class="btn btn-primary ng-binding" name="btn_search" onclick=\'core.View.Search("' + id + '")\' type="button">\
                                                        搜索</button>\
                                                </span>\
                                            </div></div>');
    }
    if (ishaveView)
    {
        $("#" + id).children().append(' <!--视图切换-->\
                                            <div class="col-xs-3 pull-right" style="margin-bottom:8px;visibility: hidden;">\
                                                <select name="ViewList" onchange="core.View.SwitchView(this,\''+ id + '\');" class="form-control col-md-3 pull-right"></select>\
                                            </div>');
    }
    $("#" + id).children().append('<!--列表-->\
                                            <div class="col-md-12" >\
                                                <div  id="ListContainer" class="col-md-12 table-responsive" style="overflow-x:visible !important; width:100%; overflow:auto;">\
                                                <div  id="ListContainer-title" class="col-md-12 table-responsive" style="overflow:visible !important; width:100%;">\
                                                <table class="table table-hover" style="table-layout:fixed" name="ListContainer">\
                                                    <colgroup>\
                                                    </colgroup>\
                                                    <thead>\
                                                    </thead>\
                                                </table>\
                                                </div>\
                                                <div  id="ListContainer-body" class="col-md-12 table-responsive" style="overflow:visible !important; width:100%;">\
                                                <table class="table table-hover" style="table-layout:fixed" name="ListContainer">\
                                                    <colgroup>\
                                                    </colgroup>\
                                                    <tbody>\
                                                    </tbody>\
                                                </table>\
                                                </div>\
                                                </div>\
                                                <nav name="ListPageing" style="float: right;">\
                                                    <ul class="pagination" style="margin: 0;">\
                                                        <li><a href="javascript:void(0);" name="pageFirst" aria-label="Firset" onclick=\'core.View.FirstPage("'+ id + '");\'><span aria-hidden="true">&laquo;</span>\
                                                        </a></li>\
                                                        <li><a href="javascript:void(0);" name="pagePrevious" aria-label="Previous" onclick=\'core.View.PrePage("' + id + '");\'><span aria-hidden="true">&lsaquo;</span>\
                                                        </a></li>\
                                                        <li><span name="pageInfo">0\0(共0条)</span></li>\
                                                        <li><a href="javascript:void(0);" name="pageNext" aria-label="Next" onclick=\'core.View.NextPage("' + id + '");\'><span aria-hidden="true">&rsaquo;</span>\
                                                        </a></li>\
                                                        <li><a href="javascript:void(0);" name="pageLast" aria-label="Last" onclick=\'core.View.LastPage("' + id + '");\'><span aria-hidden="true">&raquo;</span>\
                                                        </a></li>\
                                                    </ul>\
                                                </nav>\
                                            </div>');

    //滚动表格高度控制
    var height = window.innerHeight - 153;
    $("#ListContainer").height(height);

    core.EntityName[id] = entityname;

    core.View.GetEntityData(DefaultViewName, id);
    core.ViewName[id] = DefaultViewName;

    core.View.FilterData[id] = {};
    core.View.FilterData[id]["Conditions"] = [];

    core.View.FilterData[id]["FilterOperator"] = "AND";
    core.View.FilterData[id]["Filters"] = [];

    core.View.SearchFilter[id] = {};
    core.View.SearchFilter[id]["Conditions"] = [];
    core.View.SearchFilter[id]["FilterOperator"] = "OR";

    core.View.BindHeader(core.EntityName[id], id, InitShowView);
    var flag = 0;
    var firstIndex = -1;
    $(document).keydown(function (event)
    {
        if (event.keyCode == 16)
        {
            $(document).bind("selectstart", function () { return false; });
            flag = 1;
        }

    });
    $(document).keyup(function (event)
    {
        flag = 0;
    });

    //列表checked优化
    $(document).on('click', '#' + id + ' [name=ListContainer] tbody tr', function (e)
    {
        e = e || window.event;
        var target = e.target || e.srcElement;
        var Ocheckall = $(this).parent('tbody').parent('table').parent("div[id=ListContainer-body]").siblings("div[id=ListContainer-title]").eq(0).find('table').find('thead').find('tr').find('th:first').find('input');
        if (Ocheckall.prop('checked'))
        {
            Ocheckall.prop('checked', false);
        }
        var checkBox = $(this).find('td:first').find('input:first');
        var start = firstIndex;
        var end = $(this).index();
        var noChecked = true;
        var checkBoxStatus = $(this).find('td:first').find('input:first').prop('checked');

        if (flag == 0)
        {
            firstIndex = $(this).index();
            $("table[name=ListContainer] td input[type=checkbox][oid]").prop('checked', false);
            $('#' + id + ' [name=ListContainer] tbody tr').each(function ()
            {
                var index = $(this).index();
                if (index == end)
                {
                    $(this).css('background-color', '#CCE8FF');
                } else
                {
                    $(this).css('background-color', '#fff');
                }
            });
        }
        if (flag == 1)
        {
            $('#' + id + ' [name=ListContainer] tbody tr').each(function ()
            {
                if ($(this).find('td:first').find('input:first').prop("checked") == true)
                {
                    noChecked = false;
                }
            });
            if (noChecked)
            {
                firstIndex = $(this).index();
            } else
            {
                if (start > end)
                {
                    start = [end, end = start][0];
                }
                if (firstIndex >= 0)
                {
                    $('#' + id + ' [name=ListContainer] tbody tr').each(function ()
                    {
                        var index = $(this).index();
                        if (index >= start && index <= end)
                        {
                            $(this).find('td:first').find('input:first').prop("checked", true);
                            $(this).css('background-color', '#CCE8FF');
                        } else
                        {
                            $(this).find('td:first').find('input:first').prop("checked", false);
                            $(this).css('background-color', '#fff');
                        }
                    });
                }
            }
        }
        checkBox.prop('checked', true);

    });
    //zw 模态框绑定行选功能
    $(document).on('click', '#LookupListContainer-body tbody tr', function (e)
    {
        e = e || window.event;
        var target = e.target || e.srcElement;
        //       $('#' + id + ' [name=ListContainer] tbody tr').unbind("click");
        var checkBox = $(this).find('td:first').find('input:first');
        var OcheckBox = $(this).siblings('tr').find('td:first').find('input').prop('checked', false);
        $(this).siblings('tr').css('background-color', '#fff');
        checkBox.prop('checked', true);
        checkBox.change();
        $(this).css('background-color', '#CCE8FF');
    });


    $(document).on('click', '#LookupListContainer-body tbody tr td input', function (e)
    {
        e = e || window.event;
        var target = e.target || e.srcElement;
        var tr = $(this).parent().parent();
        var borders = tr.siblings('tr');
        borders.css('background-color', '#fff');
        if ($(this).prop("checked"))
        {
            tr.css("background-color", "#CCE8FF");
        } else
        {
            tr.css("background-color", "#fff");
        }

    });
    //zw-end
    $(document).on('click', '#' + id + ' [name=ListContainer] tbody tr td input', function (e)
    {
        e = e || window.event;
        var target = e.target || e.srcElement;
        var tr = $(this).parent().parent();
        if ($(this).prop("checked"))
        {
            tr.css("background-color", "#CCE8FF");
        } else
        {
            tr.css("background-color", "#fff");
        }

    });

    //tr双击事件
    core.View.dblclick = function (e)
    {

        var temp = e;

        core.OpenEntity(temp, 'ListInnerContainer');
    }

    $(document).on('click', '#' + id + ' [name=ListContainer] a,button,input', function (e)
    {
        //立即停止捕获/冒泡
        e.stopPropagation();
    });





}

//创建一个用户LookupList需要的模态框
core.View.CreateLookupListModal = function ()
{
    $('#myModal').modal('hide');
    core.View.CreateModal("Search for:<span id=\"modal-title-etn\"></span>", " <div class=\"input-group\">\
                                <input type=\"text\" id=\"txt_lookupsearchValue\" onkeypress=\"if (event.keyCode == 13) core.Lookup.Search();\" class=\"form-control\" placeholder=\"搜索...\" />\
                                <span class=\"input-group-btn\">\
                                    <button class=\"btn btn-primary ng-binding\" type=\"button\" onclick=\"core.Lookup.Search();\">\
                                        搜索</button>\
                                     </span></div>\
                                     <div id=\"LookupListContainer\">\
                                    <div id=\"LookupListContainer-title\">\
                                <table id=\"\" class=\"table table-condensed table-hover\">\
                                <colgroup></colgroup>\
                                <thead></thead>\
                                </table></div>\
                             <div id=\"LookupListContainer-body\">\
                            <table id=\"\" class=\"table table-condensed table-hover\">\
                        <colgroup></colgroup>\
                        <tbody></tbody>\
                        </table></div>\
</div>", "not deleted", "not deleted");
    $('#modalfooter').html("<nav id=\"ListPageing\" style=\"float: left;\">\
    <ul class=\"pagination\" style=\"margin: 0;\">\
        <li><a href=\"javascript:void(0);\" id=\"pageFirst\" aria-label=\"Firset\" onclick='core.Lookup.FirstPage();'><span aria-hidden=\"true\">&laquo;</span>\
        </a></li>\
        <li><a href=\"javascript:void(0);\" id=\"pagePrevious\" aria-label=\"Previous\" onclick='core.Lookup.PrePage();'><span aria-hidden=\"true\">&lsaquo;</span>\
        </a></li>\
        <li><span id=\"pageInfo\">1\\50</span></li>\
        <li><a href=\"javascript:void(0);\" id=\"pageNext\" aria-label=\"Next\" onclick='core.Lookup.NextPage();'><span aria-hidden=\"true\">&rsaquo;</span>\
        </a></li>\
        <li><a href=\"javascript:void(0);\" id=\"pageLast\" aria-label=\"Last\" onclick='core.Lookup.LastPage();'><span aria-hidden=\"true\">&raquo;</span>\
        </a></li>\
    </ul>\
</nav>\
<button type=\"button\" class=\"btn btn-primary ng-binding\" id=\"but_ok\">\
    确定</button>");
    return '#' + "but_ok";
}


//创建模态框
core.View.CreateModal = function (HintMsg, bodyHtml, Button1HintMsg, Button2HintMsg)
{
    $('#myModal').modal('hide');
    $('#modaldiv').children().remove();
    $('.modal-backdrop').remove();
    var BaseModal = "       <div id=\"myModal\" class=\"modal fade \" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"myModalLabel\" aria-hidden=\"true\">\
            <div class=\"modal-dialog\">\
                <div class=\"modal-content\">\
                    <div class=\"modal-header\" id=\"modalheader\">\
                        <button type=\"button\" id=\"modal_close_button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\">×</button>\
                        <h4 id=\"myModalLabel\">{0}</h4>\
                    </div>\
                    <div class=\"modal-body\" id=\"modalbody\">\
                    {1}\
                    </div>\
                    <div class=\"modal-footer\" id=\"modalfooter\">\
                        <button id=\"ModalButton1\" class=\"btn btn-primary \" aria-hidden=\"true\">{2}</button>\
                        <button class=\"btn btn-default\" data-dismiss=\"modal\" id=\"ModalButton2\" aria-hidden=\"true\">{3}</button>\
                    </div>\
                </div>\
            </div>\
        </div>";
    $('#modaldiv').append(String.format(BaseModal, HintMsg, bodyHtml, Button1HintMsg, Button2HintMsg));
    return '#' + 'ModalButton1';
}

core.View.BindHeader = function (entityname, id, InitShowView)
{
    $("#" + id + " [name=pageHeader]").text("List " + entityname);

    $("#" + id + " [name=ViewList]").html(core.Util.CreateOptions(core.EntityViews[id], core.ViewName[id]));
    $("#" + id + " [name=ViewList] option[value='']").remove();
    core.View.GenerateList(id, InitShowView);
}
core.View.GenerateList = function (id, InitShowView, pagenum, pagesize)
{
    $("#" + id + " [name=ListContainer] colgroup").html(core.View.BindListColgroup(id));

    $("#" + id + " [name=ListContainer] thead").html(core.View.BindListHeader(id));

    if ($("#" + id + " [name=ListContainer] thead .FilterDiv").length > 1)
    {
        $("#" + id + " [name=ListContainer] thead .FilterDiv:last").addClass("dropdown-menu-right");
    }
    core.View.ClearFilter(id);
    if (InitShowView)
    {
        core.View.GetListData(core.EntityName[id], JSON.stringify(core.View.FilterData[id]), id, pagenum, pagesize);
    }
}
core.View.BindListColgroup = function (id)
{
    var colNullTemplate = '<col {0} ></col>';
    var colsHTML = '<col width="35px"></col>';
    $.each(core.ViewField[id], function (i, v)
    {
        var width = (v.AttributeWidth == undefined || v.AttributeWidth == "") ? "" : v.AttributeWidth;
        switch (v.Type)
        {
            case "nvarchar":
            case "lookup":
            case "date":
            case "datetime":
            case "int":
            case "float":
            case "bit":
            case "picklist":
            case "ntext":
                colsHTML += $.format(colNullTemplate, width == "" ? "" : 'width="' + width + 'px"');
                break;
        }
    });
    if (core.View.Option[id].length != 0)
    {
        var optionWidth = (core.View.Option[id].length > 2 ? 2 : core.View.Option[id].length) * 100;
        colsHTML += "<col width='" + optionWidth + "px'></col>";
    }
    colsHTML += '<col />';
    return colsHTML;
}

core.View.BindListHeader = function (id)
{
    var filterTextTemplate = '<div class="form-group">\
                                <label for="{0}_fiterValue">筛选{2}</label>\
                                <input type="text" class="form-control" onkeypress="if (event.keyCode == 13) core.View.filter(this,\'' + id + '\')" name="{0}_fiterValue" >\
                              </div><div class="button-panel">\
                              <button type="button" attname="{0}" atttype ="{1}" class="btn btn-primary ng-binding pull-right" onclick="core.View.filter(this,\'' + id + '\')">确定</button>\
                              <button type="button" attname="{0}" atttype ="{1}" class="btn btn-primary ng-binding pull-right rebtn" onclick="core.View.filterClear(this,\'' + id + '\')">清空</button></div>';


    var test = '<input type="input" class="form-control " name="{0}_fiterValue_start" attname="{0}" atttype="{1}"  readonly/>\
                                至<input type="input" class="form-control" name="{0}_fiterValue_end" attname="{0}" atttype="{1}"  readonly/>';

    var filterDateTemplate = '<div class="form-group" atttype="datetime">\
                                <label for="{0}_fiterValue">筛选{2}</label>\
                                <input type="input" class="form-control form-time" name="{0}_fiterValue_start" atttype="datetime" onkeypress="if (event.keyCode == 13) core.View.filter(this,\'' + id + '\')">\
                                至<input type="input" class="form-control form-time" name="{0}_fiterValue_end" atttype="datetime" onkeypress="if (event.keyCode == 13) core.View.filter(this,\'' + id + '\')">\
                              </div><div class="button-panel">\
                              <button type="button" attname="{0}" atttype ="{1}" class="btn btn-primary ng-binding pull-right" onclick="core.View.filter(this,\'' + id + '\')">确定</button>\
                              <button type="button" attname="{0}" atttype ="{1}" class="btn btn-primary ng-binding pull-right rebtn" onclick="core.View.filterClear(this,\'' + id + '\')">清空</button></div>';

    //zw
    var filterFloatlate = '<div class="form-group">\
                                <label for="{0}_fiterValue">筛选{2}</label>\
                                <input type="input" class="form-control " name="{0}_fiterValue_start" onkeypress="if (event.keyCode == 13) core.View.filter(this,\'' + id + '\')">\
                                至<input type="input" class="form-control " name="{0}_fiterValue_end" onkeypress="if (event.keyCode == 13) core.View.filter(this,\'' + id + '\')">\
                              </div><div class="button-panel">\
                              <button type="button" attname="{0}" atttype ="{1}" class="btn btn-primary ng-binding pull-right" onclick="core.View.filter(this,\'' + id + '\')">确定</button>\
                              <button type="button" attname="{0}" atttype ="{1}" class="btn btn-primary ng-binding pull-right rebtn" onclick="core.View.filterClear(this,\'' + id + '\')">清空</button></div>';

    //zw-end



    var filterPicklistTemplate = '<div class="form-group">\
                                <label for="{0}_fiterValue">筛选{3}</label><div>\
                                {2}\
                              </div></div><div class="button-panel">\
                              <button type="button" attname="{0}" atttype ="{1}" class="btn btn-primary ng-binding pull-right" onclick="core.View.filter(this,\'' + id + '\')">确定</button>\
                              <button type="button" attname="{0}" atttype ="{1}" class="btn btn-primary ng-binding pull-right rebtn" onclick="core.View.filterClear(this,\'' + id + '\')">清空</button></div>';



    var listHeaderTemplate = core.View.isHaveFilter[id] ? '<th attname="{3}"><span title="点击优排序"  class="{2}" attname="{3}" {4}>{0} {1}</span><span class="dropdown"><span title="筛选" class="glyphicon glyphicon-filter" attname="{3}" data-toggle="dropdown"></span>\
    <div  class="dropdown-menu FilterDiv"style="cursor:default">{5}</div></span></th>'
    : '<th attname="{3}"><span title="点击排序"  class="{2}" attname="{3}" {4}>{0} {1}</span>\
   </th>';
    var listHeaders = "<th style='width:35px'><input  type=checkbox onclick='core.CheckAll(this)' id='checkall' ></th>";

    //先循环得到默认排序字段
    $.each(core.ViewField[id], function (i, v)
    {
        if (core.View.Orderby[id] == undefined)
        {
            if (v.ViewOrderBy != undefined)
            {
                core.View.Orderby[id] = { att: i, value: v.ViewOrderBy };
                return false;
            }
        }
    });


    $.each(core.ViewField[id], function (i, v)
    {

        switch (v.Type)
        {
            case "nvarchar":
            case "lookup":

                var filterhtml = String.format(filterTextTemplate, i, v.Type, v.DisplayName);

                if (typeof (core.View.Orderby[id]) == 'undefined' && v.IsPrimaryAtt)
                    core.View.Orderby[id] = { att: i, value: 'asc' };
                if (typeof (core.View.Orderby[id]) != 'undefined' && core.View.Orderby[id].att == i)
                    listHeaders += String.format(listHeaderTemplate, v.DisplayName, '<span class="glyphicon hdi"></span>', 'th-sort th-sort-' + core.View.Orderby[id].value, i, 'onclick="core.View.Sort(this,\'' + id + '\')"', filterhtml);
                else
                    listHeaders += String.format(listHeaderTemplate, v.DisplayName, '<span class="glyphicon hdi"></span>', 'th-sort', i, 'onclick="core.View.Sort(this,\'' + id + '\')"', filterhtml);
                break;

                //zw
            case "date":
                var filterhtml = String.format(filterDateTemplate, i, v.Type, v.DisplayName);

                if (typeof (core.View.Orderby[id]) == 'undefined' && v.IsPrimaryAtt)
                    core.View.Orderby[id] = { att: i, value: 'asc' };
                if (typeof (core.View.Orderby[id]) != 'undefined' && core.View.Orderby[id].att == i)
                    listHeaders += String.format(listHeaderTemplate, v.DisplayName, '<span class="glyphicon"></span>', 'th-sort th-sort-' + core.View.Orderby[id].value, i, 'onclick="core.View.Sort(this,\'' + id + '\')"', filterhtml);
                else
                    listHeaders += String.format(listHeaderTemplate, v.DisplayName, '<span class="glyphicon hdi"></span>', 'th-sort', i, 'onclick="core.View.Sort(this,\'' + id + '\')"', filterhtml);
                break;


            case "datetime":
                var filterhtml = String.format(filterDateTemplate, i, v.Type, v.DisplayName);

                if (typeof (core.View.Orderby[id]) == 'undefined' && v.IsPrimaryAtt)
                    core.View.Orderby[id] = { att: i, value: 'asc' };
                if (typeof (core.View.Orderby[id]) != 'undefined' && core.View.Orderby[id].att == i)
                    listHeaders += String.format(listHeaderTemplate, v.DisplayName, '<span class="glyphicon"></span>', 'th-sort th-sort-' + core.View.Orderby[id].value, i, 'onclick="core.View.Sort(this,\'' + id + '\')"', filterhtml);
                else
                    listHeaders += String.format(listHeaderTemplate, v.DisplayName, '<span class="glyphicon hdi"></span>', 'th-sort', i, 'onclick="core.View.Sort(this,\'' + id + '\')"', filterhtml);
                break;

                //zw-end
            case "int":
            case "float":
                //   var filterhtml = String.format(filterDateTemplate, i, v.Type, v.DisplayName);
                var filterhtml = String.format(filterFloatlate, i, v.Type, v.DisplayName);

                if (typeof (core.View.Orderby[id]) == 'undefined' && v.IsPrimaryAtt)
                    core.View.Orderby[id] = { att: i, value: 'asc' };
                if (typeof (core.View.Orderby[id]) != 'undefined' && core.View.Orderby[id].att == i)
                    listHeaders += String.format(listHeaderTemplate, v.DisplayName, '<span class="glyphicon"></span>', 'th-sort th-sort-' + core.View.Orderby[id].value, i, 'onclick="core.View.Sort(this,\'' + id + '\')"', filterhtml);
                else
                    listHeaders += String.format(listHeaderTemplate, v.DisplayName, '<span class="glyphicon hdi"></span>', 'th-sort', i, 'onclick="core.View.Sort(this,\'' + id + '\')"', filterhtml);
                break;
            case "bit":
                var radios = core.Util.CreateRadios("filter" + i, [{ Value: 0, Text: '否' }, { Value: 1, Text: '是' }]);
                var filterhtml = String.format(filterPicklistTemplate, i, v.Type, radios, v.DisplayName);

                if (typeof (core.View.Orderby[id]) == 'undefined' && v.IsPrimaryAtt)
                    core.View.Orderby[id] = { att: i, value: 'asc' };
                if (typeof (core.View.Orderby[id]) != 'undefined' && core.View.Orderby[id].att == i)
                    listHeaders += String.format(listHeaderTemplate, v.DisplayName, '<span class="glyphicon hdi"></span>', 'th-sort th-sort-' + core.View.Orderby[id].value, i, 'onclick="core.View.Sort(this,\'' + id + '\')"', filterhtml);
                else
                    listHeaders += String.format(listHeaderTemplate, v.DisplayName, '<span class="glyphicon hdi"></span>', 'th-sort', i, 'onclick="core.View.Sort(this,\'' + id + '\')"', filterhtml);
                break;
            case "picklist":
                var Checkbox = core.Util.CreateCheckbox("filter" + i, core.EntityOption[id][i]);
                var filterhtml = String.format(filterPicklistTemplate, i, v.Type, Checkbox, v.DisplayName);

                if (typeof (core.View.Orderby[id]) == 'undefined' && v.IsPrimaryAtt)
                    core.View.Orderby[id] = { att: i, value: 'asc' };
                if (typeof (core.View.Orderby[id]) != 'undefined' && core.View.Orderby[id].att == i)
                    //           listHeaders += String.format(listHeaderTemplate, v.DisplayName, '<span class="glyphicon"></span>', 'th-sort th-sort-' + core.View.Orderby[id].value, i, 'onclick="core.View.Sort(this,\'' + id + '\')"', filterhtml);
                    listHeaders += String.format(listHeaderTemplate, v.DisplayName, '<span class="glyphicon hdi"></span>', 'th-sort th-sort-' + core.View.Orderby[id].value, i, 'onclick="core.View.Sort(this,\'' + id + '\')"', filterhtml);
                else
                    //           listHeaders += String.format(listHeaderTemplate, v.DisplayName, '<span class="glyphicon"></span>', 'th-sort', i, 'onclick="core.View.Sort(this,\'' + id + '\')"', filterhtml);
                    listHeaders += String.format(listHeaderTemplate, v.DisplayName, '<span class="glyphicon hdi"></span>', 'th-sort', i, 'onclick="core.View.Sort(this,\'' + id + '\')"', filterhtml);
                break;
            case "ntext":
                var filterhtml = String.format(filterTextTemplate, i, v.Type, v.DisplayName);
                listHeaders += String.format(listHeaderTemplate, v.DisplayName, null, null, null, null, filterhtml);
                break;
            case "key":
                //listHeaders += String.format(listHeaderTemplate, "");
                break;
        }
    });
    if (core.View.Orderby[id] == undefined)
    {
        $.each(core.ViewField[id], function (i, v)
        {
            if (core.View.Orderby[id] == undefined)
            {
                switch (v.Type)
                {
                    case "nvarchar":
                    case "lookup":
                    case "date":
                    case "datetime":
                    case "int":
                    case "float":
                    case "bit":
                    case "picklist":
                        core.View.Orderby[id] = { att: i, value: 'asc' }
                        break;
                }
            }
        });
    }

    if (core.View.Option[id].length != 0)
    {
        listHeaders += "<th>操作</th>";
    }
    listHeaders += "<th></th>";
    return String.format('<tr>{0}</tr>', listHeaders);

}
core.View.BindListItem = function (data, id)
{
    core.ListData[id] = data;
    var rowTemplate = '<tr etn="{0}" oid="{1}" ondblclick="core.View.dblclick(this)">{2}</tr>'
    var colCheckBoxTemplate = '<td><input type="checkbox"  etn="{0}" oid="{1}"/></td>';
    var colTextTemplate = '<td>{0}</td>';
    var colLookupTemplate = '<td><a href="#" etn="{2}" oid="{1}" onclick="core.OpenEntity(this,\'' + id + '\');" style="color:#333">{0}</a></td>';
    var colPickTemplate = '<td>{0}</td>';
    var colUniqueTemplate = '<td><a href="#" etn="{0}" oid="{1}" onclick="core.OpenEntity(this,\'' + id + '\');"><span class="glyphicon glyphicon-tags small"></span> {2}</a></td>';
    var colBitTemplate = '<td>{0}</td>';

    var rows = "";
    $.each(core.ListData[id].List, function (i, v)
    {
        var cols = String.format(colCheckBoxTemplate, core.EntityName[id], v[core.EntityName[id] + "id"]);
        $.each(core.ViewField[id], function (key, value)
        {
            switch (value.Type)
            {
                case "ntext":
                case "nvarchar":
                    if (value.IsPrimaryAtt)
                        cols += String.format(colUniqueTemplate, core.EntityName[id], v[core.EntityName[id] + "id"], v[key]);
                    else
                    {
                        if (v[key] != undefined && v[key] != null)
                            cols += String.format(colTextTemplate, v[key].replace(/\r\n/g, "<br \/>").replace(/\r/g, "<br \/>").replace(/\n/g, "<br \/>"));
                        else
                            cols += String.format(colTextTemplate, v[key]);
                    }
                    break;
                case "int":
                case "date":
                case "datetime":
                case "float":
                    cols += String.format(colTextTemplate, v[key]);
                    break;
                case "picklist":
                    cols += String.format(colPickTemplate, core.Util.GetOptionText(core.EntityOption[id][key], v[key]));
                    break;
                case "bit":
                    cols += String.format(colBitTemplate, v[key] ? "是" : (v[key] == false ? "否" : ""));
                    break;
                case "lookup":
                    if (v[key] == null)
                    {
                        cols += "<td></td>";
                    }
                    else
                    {
                        //lookup字段不能打开
                        cols += String.format(colLookupTemplate, v[key]["name"], v[key]["id"], v[key]["entityname"]);
                    }
                    break;
                case "key":
                    //listHeaders += String.format(listHeaderTemplate, "");
                    break;
            }
        });

        if (core.View.Option[id].length != 0)
        {
            cols += "<td>";
            for (var i in core.View.Option[id])
            {
                var display = "";
                if (core.View.Option[id][i]["display"] == "none")
                {
                    display = "style='display:none;' "
                }
                cols += "<button type='button' " + display + " class='btn ViewOptionBtn' onclick='" + core.View.Option[id][i]["function"] + ";'>" + core.View.Option[id][i]["name"] + "</button>  ";
            }
            cols += "</td>";
        }
        cols += "<td></td>";
        rows += String.format(rowTemplate, core.EntityName[id], v[core.EntityName[id] + "id"], cols);


    })

    return rows;

}
core.View.BindListPageing = function (id)
{
    var pageingTemplate = '{0}\\{1}(共{2}条)';
    var total = core.ListData[id].Total;
    var size = core.ListData[id].Size;
    var index = total == 0 ? 0 : core.ListData[id].Index + 1;
    var pages = Math.ceil(total / size);
    $("#" + id + " [name=pageInfo]").text(String.format(pageingTemplate, index, pages, total));
    if (total != 0)
    {
        $("#" + id + " [name=pageFirst]").parent().removeClass("disabled");
        $("#" + id + " [name=pagePrevious]").parent().removeClass("disabled");
        $("#" + id + " [name=pageLast]").parent().removeClass("disabled");
        $("#" + id + " [name=pageNext]").parent().removeClass("disabled");
        if (index == 1)
        {
            $("#" + id + " [name=pageFirst]").parent().addClass("disabled");
            $("#" + id + " [name=pagePrevious]").parent().addClass("disabled");
        }
        if (index == pages)
        {
            $("#" + id + " [name=pageLast]").parent().addClass("disabled");
            $("#" + id + " [name=pageNext]").parent().addClass("disabled");
        }
    }
    else
    {
        $("#" + id + " [name=pageFirst]").parent().addClass("disabled");
        $("#" + id + " [name=pagePrevious]").parent().addClass("disabled");
        $("#" + id + " [name=pageLast]").parent().addClass("disabled");
        $("#" + id + " [name=pageNext]").parent().addClass("disabled");
    }
}

core.View.Sort = function (src, id)
{
    var $this = $(src);

    $this.find("span").removeClass("hdi");

    if ($this.attr("attname") != core.View.Orderby[id].att)
    {
        var $curSort = $this.parent().parent().find(".th-sort[attname=" + core.View.Orderby[id].att + "]");
        //      alert($curSort.html());
        $curSort.removeClass("th-sort-asc");
        $curSort.removeClass("th-sort-desc");
        $this.addClass("th-sort-asc");
        core.View.Orderby[id].value = "asc";
        core.View.Orderby[id].att = $this.attr("attname");

    }
    else
    {
        if ($this.hasClass("th-sort-asc"))
        {
            $this.removeClass("th-sort-asc");
            $this.addClass("th-sort-desc");
            core.View.Orderby[id].value = "desc";
        }
        else
        {
            $this.removeClass("th-sort-desc");
            $this.addClass("th-sort-asc");
            core.View.Orderby[id].value = "asc";
        }
    }

    core.View.GetListData(core.EntityName[id], JSON.stringify(core.View.FilterData[id]), id);

};

core.View.Search = function (id)
{

    var searchValue = $("#" + id + " [name=txt_searchValue]").val();
    core.View.SearchFilter[id] = {};
    core.View.SearchFilter[id]["Conditions"] = [];
    core.View.SearchFilter[id]["FilterOperator"] = "OR";
    core.View.FilterData[id]["Filters"] = [];
    if (searchValue != "")
    {
        $.each(core.ViewField[id], function (i, v)
        {
            if (v.Type != 'datetime' && v.Type != 'date' && v.Type != 'picklist')
            {
                var ConditionExpression = {};
                ConditionExpression["AttributeName"] = i;
                ConditionExpression["Operator"] = "like";
                if (v.Type == 'lookup')
                {
                    var lookup = {};
                    lookup["name"] = "*" + searchValue;
                    lookup["id"] = null;
                    ConditionExpression["Values"] = [lookup];
                }
                else
                {
                    ConditionExpression["Values"] = ["*" + searchValue];
                }
                core.View.SearchFilter[id]["Conditions"].push(ConditionExpression);
            }
        });

    }
    if (core.View.SearchFilter[id]["Conditions"].length != 0)
    {
        core.View.FilterData[id]["Filters"].push(core.View.SearchFilter[id]);
    }
    core.View.GetListData(core.EntityName[id], JSON.stringify(core.View.FilterData[id]), id);
}


core.View.GetListData = function (etn, filterData, id, pagenum, pagesize)
{
    $.TL_LockScreen();

    var order = String.format("{0} {1}"
            , core.View.Orderby[id].att + (core.ViewField[id][core.View.Orderby[id].att].Type == "lookup" ? "name" : "")
            , core.View.Orderby[id].value);

    if (pagenum == undefined)
        pagenum = (core.View.PageParam[id] ? core.View.PageParam[id].pagenum : 0);
    if (pagesize == undefined)
        pagesize = (core.View.PageParam[id] ? core.View.PageParam[id].pagesize : 50);
    if (core.View.LinkEntity)
    {
        $.ajax({
            type: "post",
            url: "/Service/Data/N2N.ashx",
            data: {
                "aid": core.View.LinkEntity.aid,
                "Function": "Read",
                "EntityA": core.View.LinkEntity.EntityA,
                "EntityM": core.View.LinkEntity.EntityM,
                "EntityB": core.View.LinkEntity.EntityB,
                "filter": filterData,
                "order": order,
                "pagenum": pagenum,
                "pagesize": pagesize,
                "ViewName": core.ViewName[id]
            },
            dataType: "json",
            success: function (data, textStatus)
            {
                $.TL_unLockScreen();
                $("#" + id + " [name=ListContainer] tbody").html(core.View.BindListItem(data, id));

                core.View.BindListPageing(id);
            },
            error: Common.AjaxError
        });
    }
    else
    {
        $.ajax({
            type: "post",
            url: ((core.View.Url[id] == "" || core.View.Url[id] == undefined) ? "/Service/Data/GetListData.ashx" : core.View.Url[id]),
            dataType: "json",
            data: { entityname: etn, order: order, pagenum: pagenum, pagesize: pagesize, filter: filterData, ViewName: core.ViewName[id] },
            success: function (data, textStatus)
            {
                $.TL_unLockScreen();
                $("#" + id + " [name=ListContainer] tbody").html(core.View.BindListItem(data, id));

                core.View.BindListPageing(id);

                if (typeof (core.View.DoAfterView) == 'function')
                {
                    core.View.DoAfterView(id);
                }

            },
            error: Common.AjaxError
        });
    }
}

core.View.NextPage = function (id)
{
    if (!$("#" + id + " [name=pageNext]").parent().hasClass("disabled"))
    {
        core.View.GetListData(core.EntityName[id], JSON.stringify(core.View.FilterData[id]), id, core.ListData[id].Index + 1);
    }
}

core.View.PrePage = function (id)
{
    if (!$("#" + id + " [name=pagePrevious]").parent().hasClass("disabled"))
    {
        core.View.GetListData(core.EntityName[id], JSON.stringify(core.View.FilterData[id]), id, core.ListData[id].Index - 1);
    }
}

core.View.LastPage = function (id)
{
    if (!$("#" + id + " [name=pageLast]").parent().hasClass("disabled"))
    {
        var total = core.ListData[id].Total;
        var size = core.ListData[id].Size;
        var pages = Math.ceil(total / size);
        core.View.GetListData(core.EntityName[id], JSON.stringify(core.View.FilterData[id]), id, pages - 1);
    }
}

core.View.FirstPage = function (id)
{
    if (!$("#" + id + " [name=pageFirst]").parent().hasClass("disabled"))
    {
        core.View.GetListData(core.EntityName[id], JSON.stringify(core.View.FilterData[id]), id, 0);
    }
}




//filter
core.View.FilterData = {};
core.View.SearchFilter = {};


core.View.filter = function (src, id)
{
    if (src.nodeName == 'BUTTON')
    {
        var attname = $(src).attr("attname");
        var atttype = $(src).attr("atttype");
        var Val1 = $(src).parent().siblings().find("input").eq(0).val();
        var Val2 = $(src).parent().siblings().find("input").eq(1).val();
    }
    if (src.nodeName == 'INPUT')
    {
        var attname = $(src).parent().siblings().find("button").eq(1).attr("attname");
        var atttype = $(src).parent().siblings().find("button").eq(1).attr("atttype");
        var Val1 = $(src).eq(0).val();
        var Val2 = $(src).siblings("input").val();
        if ($(src).index() == "2")
        { var content; content = Val1; Val1 = Val2; Val2 = content; }
    }
    var ConditionExpression = {};
    ConditionExpression["AttributeName"] = attname;

    for (var i = 0; i < core.View.FilterData[id]["Conditions"].length; i++)
    {
        if (core.View.FilterData[id]["Conditions"][i]["AttributeName"] == attname)
        {
            core.View.FilterData[id]["Conditions"].splice(i, 1)
        }
    }

    if (atttype == "datetime")
    {
        if ((Val1 == "") && (Val2 == ""))
        {
            alert("请输入日期！");
            return
        }
        var regexp = new RegExp("^([1][7-9][0-9][0-9]|[2][0][0-9][0-9])(\-)([0][1-9]|[1][0-2])(\-)([0-2][1-9]|[3][0-1])( )([0-1][0-9]|[2][0-3])(:)([0-5][0-9])$");
        if (Val1 != "" && (!regexp.test(Val1)))
        {
            alert("请输入正确的开始时间！");
            return
        }
        if (Val2 != "" && (!regexp.test(Val2)))
        {
            alert("请输入正确的截止时间！");
            return
        }
    }
    else if (atttype == "int")
    {
        if ((Val1 == "") && (Val2 == ""))
        {
            alert("请输入值！");
            return;
        }
        var reg = new RegExp("^[0-9]+$");
        if (Val1 != "" && (!reg.test(Val1)))
        {
            alert("请输入正确的起始值！");
            return;
        }
        if (Val2 != "" && (!reg.test(Val2)))
        {
            alert("请输入正确的截止值！");
            return;
        }
    }
    switch (atttype)
    {
        case "nvarchar":

            //break;
        case "ntext":
            var filtervalue = $.trim($("#" + id + " [name=" + attname + "_fiterValue]").val());
            if (filtervalue != "")
            {

                ConditionExpression["Operator"] = "Like";
                ConditionExpression["Values"] = ["*" + filtervalue];

                core.View.FilterData[id]["Conditions"].push(ConditionExpression);
            }
            break;
        case "lookup":
            var filtervalue = $.trim($("#" + id + " [name=" + attname + "_fiterValue]").val());
            if (filtervalue != "")
            {

                ConditionExpression["Operator"] = "Like";

                var lookup = {};
                lookup["Name"] = "*" + filtervalue;
                lookup["id"] = null;
                ConditionExpression["Values"] = [];
                ConditionExpression["Values"].push(lookup);
                //ConditionExpression["Values"] = [{ "Name": filtervalue }];

                core.View.FilterData[id]["Conditions"].push(ConditionExpression);
            }
            break;
        case "date":
            //break;
            //zw           
        case "datetime":

            //break;
        case "int":

            //break;
            //zw-end
        case "float":
            var filtervalue_start = $.trim($("#" + id + " [name=" + attname + "_fiterValue_start]").val());
            var filtervalue_end = $.trim($("#" + id + " [name=" + attname + "_fiterValue_end]").val());
            if (filtervalue_start != "" && filtervalue_end != "")
            {

                ConditionExpression["Operator"] = "between";
                ConditionExpression["Values"] = [filtervalue_start, filtervalue_end];
                core.View.FilterData[id]["Conditions"].push(ConditionExpression);
            }
            else if (filtervalue_start != "")
            {

                ConditionExpression["Operator"] = "GreaterEqual";
                ConditionExpression["Values"] = [filtervalue_start];
                core.View.FilterData[id]["Conditions"].push(ConditionExpression);
            }
            else if (filtervalue_end != "")
            {

                ConditionExpression["Operator"] = "LessEqual";
                ConditionExpression["Values"] = [filtervalue_end];
                core.View.FilterData[id]["Conditions"].push(ConditionExpression);
            }

            break;

        case "bit":

            ConditionExpression["Operator"] = "in";
            ConditionExpression["Values"] = [];


            if ($("#" + id + " input:radio[name=filter" + attname + "]:checked").length != 0)
            {
                ConditionExpression["Values"].push($("#" + id + " input:radio[name=filter" + attname + "]:checked").val());
            }
            if (ConditionExpression["Values"].length != 0)
            {
                core.View.FilterData[id]["Conditions"].push(ConditionExpression);
            }
            break;
        case "picklist":


            ConditionExpression["Operator"] = "in";
            ConditionExpression["Values"] = [];


            $("#" + id + " [name=filter" + attname + "]:checked").each(function ()
            {
                ConditionExpression["Values"].push($(this).val());
            });
            if (ConditionExpression["Values"].length != 0)
            {
                core.View.FilterData[id]["Conditions"].push(ConditionExpression);
            }
            break;
        case "key":
            break;
    }
    core.View.GetListData(core.EntityName[id], JSON.stringify(core.View.FilterData[id]), id);
}

core.View.filterClear = function (src, id)
{
    var attname = $(src).attr("attname");
    var atttype = $(src).attr("atttype");


    switch (atttype)
    {
        case "nvarchar":

        case "ntext":
        case "lookup":
            $("#" + id + " [name=" + attname + "_fiterValue]").val("");
            break;
        case "date":
        case "datetime":
        case "int":
        case "float":
            $("#" + id + " [name=" + attname + "_fiterValue_start]").val("");
            $("#" + id + " [name=" + attname + "_fiterValue_end]").val("");
            break;
        case "bit":
        case "picklist":
            $("#" + id + " [name=filter" + attname + "]:checked").attr("checked", false);
            break;
        case "key":
            break;
    }

    for (var i = 0; i < core.View.FilterData[id]["Conditions"].length; i++)
    {
        if (core.View.FilterData[id]["Conditions"][i]["AttributeName"] == attname)
        {
            core.View.FilterData[id]["Conditions"].splice(i, 1)
        }
    }
    core.View.GetListData(core.EntityName[id], JSON.stringify(core.View.FilterData[id]), id);
}


core.View.SwitchView = function (src, id)
{
    //core.ViewName[id] = $(src).val();
    //重新获取Field
    //var UrlBase = "/Pages/DataPages/ViewPage.aspx?entityname={0}&viewname={1}";
    //window.location.href = String.format(UrlBase, EntityName, $(src).val());
    var search;
    if (window.location.search.match(/viewname=[\x00-\x25\x27-\xff]*(?=\&|$)/g) == null)
    {
        if (window.location.search.match(new RegExp("[\?\&][^\?\&]+=[^\?\&]+", "g")) != null)
        {
            search = window.location.search += "&viewname=" + $(src).val();
        } else
        {
            search = window.location.search += "?viewname=" + $(src).val();
        }
    } else
    {
        search = window.location.search.replace(/viewname=[\x00-\x25\x27-\xff]*(?=\&|$)/g, "viewname=" + $(src).val());
    }
    window.location.href = window.location.origin + window.location.pathname + search;
}

core.View.GetEntityData = function (ViewName, id)
{
    if (typeof (ViewName) == 'undefined')
    {
        ViewName = null;
    }
    $.ajax({
        type: "post",
        url: "/Service/Data/GetEntityField.ashx",
        dataType: "json",
        async: false,
        data: {
            entityname: core.EntityName[id], viewname: ViewName
        },
        success: function (data, textStatus)
        {

            core.ViewField[id] = data["Fields"];

            core.EntityOption[id] = data["Options"];
            core.EntityViews[id] = data["Views"];

        },
        error: Common.AjaxError
    });



}


core.View.Refresh = function (id)
{
    core.View.GetListData(core.EntityName[id], JSON.stringify(core.View.FilterData[id]), id, core.ListData[id].Index);
    $("[name=ListContainer] input[type=checkbox][id='checkall']").prop('checked', false);
}

core.View.AddButton = function (id, text, glyphicons)
{
    var ButtonHtml = "<span id=\"span_" + id + "\"><a class=\"btn btn-primary ng-binding\" title=\"AddExist\" id=\"{0}\"><span class=\"glyphicon {1}\"></span>&nbsp;{2}</a></span>";
    var textHtml = "<span class=\"glyphicon {0}\"></span>&nbsp;{1}";
    if ($('#' + id).length <= 0)
        $('#buttonheader').append(String.format(ButtonHtml, id, glyphicons, text));
    else $('#' + id).html(String.format(textHtml, glyphicons, text));
    return '#' + id;
}

core.View.ClearFilter = function (id)
{
    $("#" + id + " [name=txt_searchValue]").val("");
}

//滚动表格高度响应
function windowResize()
{
    var searchHeight = $("#searchContainer").height();
    var height = window.innerHeight - (searchHeight == null ? 153 : (searchHeight + 135));
    $("#ListContainer").height(height);
}
$(window).resize(windowResize);

//$(function(){ShowSearchHTML(["owninguser","tlm_name"])});//调用
function ShowSearchHTML(cols)
{
    $("select[name=ViewList]").parent().hide();
    var SearchContainer = $("input[name=txt_searchValue]").parents("[class='col-xs-6']").attr("id", "searchContainer");
    SearchContainer.removeClass().css("padding", "10px 20px 10px 20px");
    var innerHtml = "";
    $.each(cols, function (i, v)
    {
        if (core.ViewField[id][v] != undefined)
        {
            var displayName = core.ViewField[id][v].DisplayName;
            if (displayName.length == 1) displayName = "　　　　" + displayName;
            if (displayName.length == 2) displayName = "　　　" + displayName;
            if (displayName.length == 3) displayName = "　　" + displayName;
            if (displayName.length == 4) displayName = "　" + displayName;
            if (displayName.length == 5) displayName = "" + displayName;

            var attrType = core.ViewField[id][v].Type;
            var controlHtml = "";
            controlHtml = '<input type="input" class="form-control" searchattr="' + v + '" searchtype="' + attrType + '" name="' + v + '_searchValue"/>';
            switch (attrType)
            {
                case "date":
                    break;
                case "datetime":
                    controlHtml = '<input type="input" class="form-control form-time" name="{0}_searchValue_start" searchtype="{1}" searchattr="{0}" placeholder="Start" onkeypress="if (event.keyCode == 13) $(\'#searchContainer [name=btn_search]\').click()"/>\
                                   <label>&nbsp;~&nbsp;</label><input type="input" class="form-control form-time" name="{0}_searchValue_end" searchtype="{1}" searchattr="{0}" placeholder="End" oonkeypress="if (event.keyCode == 13) $(\'#searchContainer [name=btn_search]\').click()"/>';
                    controlHtml = String.format(controlHtml, core.ViewField[id][v].Name, attrType);
                    break;
                case "int":
                case "float":
                    controlHtml = '<input type="input" class="form-control" name="{0}_searchValue_start" searchtype="{1}" searchattr="{0}" placeholder="Start" onkeypress="if (event.keyCode == 13) $(\'#searchContainer [name=btn_search]\').click()"/>\
                                   <label>&nbsp;~&nbsp;</label><input type="input" class="form-control" name="{0}_searchValue_end" searchtype="{1}" searchattr="{0}" placeholder="End" onkeypress="if (event.keyCode == 13) $(\'#searchContainer [name=btn_search]\').click()"/>';
                    controlHtml = String.format(controlHtml, core.ViewField[id][v].Name, attrType);
                    break;
                case "bit":
                    controlHtml = '<select class="form-control" searchattr="' + v + '" searchtype="' + attrType + '" name="search' + v + '" onchange="$(\'#searchContainer [name=btn_search]\').click()><option value="" selected>--全部--</option>\
                                   <option value="0">否</option>\
                                   <option value="1">是</option>\
                                   </select>';
                    break;
                case "picklist":
                    controlHtml = '<select class="form-control" searchattr="' + v + '" searchtype="' + attrType + '" name="search' + v + '" onchange="$(\'#searchContainer [name=btn_search]\').click()"><option value="" selected>--全部--</option>';
                    $.each(core.EntityOption[id][v], function (i, v)
                    {
                        controlHtml += '<option value="' + v.Value + '">' + v.Text + '</option>';
                    });
                    controlHtml += "</select>";
                    break;
                case "lookup":
                case "ntext":
                case "nvarchar":
                case "text":
                    controlHtml = '<input type="input" class="form-control" searchattr="' + v + '" searchtype="' + attrType + '" name="' + v + '_searchValue" onkeypress="if (event.keyCode == 13) $(\'#searchContainer [name=btn_search]\').click()"/>';
                    break;
                default:
                    controlHtml = '<input type="input" class="form-control" searchattr="' + v + '" searchtype="' + attrType + '" name="' + v + '_searchValue" onkeypress="if (event.keyCode == 13) $(\'#searchContainer [name=btn_search]\').click()"/>';
                    break;
            }
            innerHtml += '<div><label>' + displayName + '</label>' + controlHtml + '</div>';
        }
    });
    innerHtml += '<button class="btn btn-primary ng-binding" name="btn_search" type="button" style="margin:0 0 0 20px;height:30px;" onclick="core.View.filterExtral(this,\'' + id + '\')"><span style="line-height:5px;display:block;">搜索<span></button>';
    innerHtml += '<button class="btn btn-primary ng-binding" name="btn_clear" type="button" style="margin:0 0 0 5px;height:30px;" onclick="core.View.ClearFilterExtral()"><span style="line-height:5px;display:block;">清空<span></button>';
    SearchContainer.html(innerHtml);

    $('.form-time').datetimepicker({
        language: 'zh-CN',
        format: 'yyyy-mm-dd hh:ii',
        weekStart: 1,
        autoclose: true
    });

    $("input[searchtype=datetime]").click(function ()
    {
        var Fiterpanel = $(this).parent().children('.SearchDiv').eq(0);
        Fiterpanel.css({ "top": $(this).offset().top + $(this).height(), "left": $(this).offset().left });
    });
    SearchContainer.find("div").css({ "display": "inline-block", "width": "230px" });
    SearchContainer.find("label").css({ "font-weight": "normal", "padding": "5px", "display": "inline-block" });
    SearchContainer.find("input").css({ "width": "150px", "height": "25px", "display": "inline-block" });
    SearchContainer.find("select").css({ "width": "150px", "height": "25px", "padding": "0px", "display": "inline-block" });
    windowResize();
    //createdon等长度控制
    $("#searchContainer").children().each(function ()
    {
        if ($(this).find("input").length == 2)
        {
            $(this).css({ "width": "460px" });
            $(this).find("input").eq(0).css({ "width": "175px" });
            $(this).find("input").eq(1).css({ "width": "175px" });
        }
    });
}

core.View.filterExtral = function (src, id)
{
    var container = $(src).parent();
    container.find("[searchattr]").each(function ()
    {
        var ConditionExpression = {};
        var attname = $(this).attr("searchattr");
        ConditionExpression["AttributeName"] = $(this).attr("searchattr");
        var searchtype = $(this).attr("searchtype");
        switch (searchtype)
        {
            case "nvarchar":
            case "ntext":
                var searchValue = $.trim($("#" + id + " [name=" + attname + "_searchValue]").val());
                if (searchValue != "")
                {
                    ConditionExpression["Operator"] = "Like";
                    ConditionExpression["Values"] = ["*" + searchValue];
                    core.View.FilterData[id]["Conditions"].push(ConditionExpression);
                }
                break;
            case "lookup":
                var searchValue = $.trim($("#" + id + " [name=" + attname + "_searchValue]").val());
                if (searchValue != "")
                {
                    ConditionExpression["Operator"] = "Like";
                    var lookup = {};
                    lookup["Name"] = "*" + searchValue;
                    lookup["id"] = null;
                    ConditionExpression["Values"] = [];
                    ConditionExpression["Values"].push(lookup);
                    core.View.FilterData[id]["Conditions"].push(ConditionExpression);
                }
                break;
            case "date":
            case "datetime":
            case "int":
            case "float":
                var searchvalue_start = $.trim($("#" + id + " [name=" + attname + "_searchValue_start]").val());
                var searchvalue_end = $.trim($("#" + id + " [name=" + attname + "_searchValue_end]").val());
                if (searchvalue_start != "" && searchvalue_end != "")
                {
                    ConditionExpression["Operator"] = "between";
                    ConditionExpression["Values"] = [searchvalue_start, searchvalue_end];
                    core.View.FilterData[id]["Conditions"].push(ConditionExpression);
                }
                else if (searchvalue_start != "")
                {
                    ConditionExpression["Operator"] = "GreaterEqual";
                    ConditionExpression["Values"] = [searchvalue_start];
                    core.View.FilterData[id]["Conditions"].push(ConditionExpression);
                }
                else if (searchvalue_end != "")
                {
                    ConditionExpression["Operator"] = "LessEqual";
                    ConditionExpression["Values"] = [searchvalue_end];
                    core.View.FilterData[id]["Conditions"].push(ConditionExpression);
                }
                break;
            case "bit":
            case "picklist":
                ConditionExpression["Operator"] = "in";
                ConditionExpression["Values"] = [];
                ConditionExpression["Values"].push($("#" + id + " [name=search" + attname + "]").val());
                if (ConditionExpression["Values"][0] != "")
                {
                    core.View.FilterData[id]["Conditions"].push(ConditionExpression);
                }
                break;
            case "key":
                break;
        }
    });
    core.View.GetListData(core.EntityName[id], JSON.stringify(core.View.FilterData[id]), id);
    core.View.FilterData[id]["Conditions"] = [];//初始化Conditions
    return;
}

core.View.ClearFilterExtral = function ()
{
    $("#searchContainer input").val("");
    $("#searchContainer select").val("");
    $("#searchContainer [name=btn_search]").click();
}
